package com.gsm.service.impl;

import com.gsm.dao.WebChartDao;
import com.gsm.entity.Result;
import com.gsm.po.RotationChart;
import com.gsm.service.WebChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WebChartServiceImpl implements WebChartService {
    @Autowired
    private WebChartDao webChartDao;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public Result selectRotationChartList() {
        List<RotationChart> list;
        ValueOperations<String, Object> ops = redisTemplate.opsForValue();
        list = (List<RotationChart>) ops.get("chart:list");
        if (list != null) {
            return Result.success(list);
        }
        list = webChartDao.selectRotationChartList();
        ops.set("chart:list", list);
        return Result.success(list);
    }
}
